package com.yl.chainStore.control.sick

import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.yl.chainStore.common.Constants
import com.yl.chainStore.common.enums.Status
import com.yl.chainStore.common.enums.TypeEnum
import com.yl.chainStore.control.BaseCtrl
import com.yl.chainStore.entity.sick.SickCustomerAccessLog
import com.yl.chainStore.entity.sick.SickCustomerAccessLogPlan
import com.yl.chainStore.pojo.vo.company.SickCustomerAccessLogModelSelectVo
import com.yl.chainStore.pojo.vo.pay.PayCustomerOrderDetailSelectVo
import com.yl.chainStore.pojo.vo.sick.SickCustomerAccessLogCompleteVo
import com.yl.chainStore.pojo.vo.sick.SickCustomerAccessLogSelectVo
import com.yl.chainStore.services.ICompanyDictionaryService
import com.yl.chainStore.services.ICustomerInfoService
import com.yl.chainStore.services.IWebCompanyDeptService
import com.yl.chainStore.services.IWebCompanyUserService
import com.yl.chainStore.services.sick.ISickCustomerAccessLogModelService
import com.yl.chainStore.services.sick.ISickCustomerAccessLogService
import com.yl.chainStore.util.addTimeByType
import com.yl.common.ErrorCode
import com.yl.common.control.ResponseBody
import com.yl.common.control.returnError
import com.yl.common.control.returnSuccess
import com.yl.common.getContext
import com.yl.users.common.annotations.PermsCode
import com.yl.users.entity.CompanyUser
import com.yl.users.services.ICompanyUserService
import org.springframework.transaction.annotation.Transactional
import org.springframework.transaction.interceptor.TransactionAspectSupport
import org.springframework.web.bind.annotation.*
import java.lang.Exception
import java.util.*



/**
 * 随访相关页面
 * @author cxw
 */
@RestController
@RequestMapping("sick/accessLog")
open class CustomerAccessLogController(
	private val iCustomerInfoService: ICustomerInfoService,
	private val iSickCustomerAccessLogService: ISickCustomerAccessLogService,
	private val iWebCompanyDeptService: IWebCompanyDeptService,
	private val iCompanyUserService: ICompanyUserService,
	private val iCompanyDictionaryService: ICompanyDictionaryService,
	private val iWebCompanyUserService: IWebCompanyUserService,

	private val iSickCustomerAccessLogModelService: ISickCustomerAccessLogModelService
) : BaseCtrl() {

	/**customer_subscribe_item
	 * 客户随访列表查询
	 */
	@PostMapping("getLogList")
	@PermsCode("customer:access:follow:show")
	@Transactional
	open fun getLogList(@RequestBody vo: SickCustomerAccessLogSelectVo): ResponseBody {
		vo.type = TypeEnum.ACCESS_LOG_FOLLOW_UP
		val accessLogList = iCustomerInfoService.getAccessLogList(vo)
		for (accessLog in accessLogList) {
			iCustomerInfoService.getJoinInfoByCustomerId(accessLog.customerId,accessLog)
		}
		return returnSuccess(accessLogList)
	}

	/**customer_subscribe_item
	 * 客户随访列表查询
	 */
	@PostMapping("getFollowLogPage")
	@Transactional
//	@PermsCode("customer:access:follow:show")
	open fun getLogPage(@RequestBody vo: SickCustomerAccessLogSelectVo): ResponseBody {
		vo.type = TypeEnum.ACCESS_LOG_FOLLOW_UP
		val accessLogPage = iCustomerInfoService.getAccessLogPage(Page(vo.current, vo.size), vo)
		for (accessLog in accessLogPage.records) {
			iCustomerInfoService.getJoinInfoByCustomerId(accessLog.customerId,accessLog)
		}
		return returnSuccess(accessLogPage)
	}

	/**
	 * 用户的随访列表
	 */
	@PostMapping("getUserFollowLogList")
	@Transactional
	open fun getUserFollowLogList(@RequestBody vo: SickCustomerAccessLogSelectVo): ResponseBody {
		val followLogList = iWebCompanyUserService.getFollowLogList(getContext().userId, vo)
		for (accessLog in followLogList) {
			iCustomerInfoService.getJoinInfoByCustomerId(accessLog.customerId,accessLog)
		}
		return returnSuccess(followLogList)
	}

	/**
	 * 用户的随访分页
	 */
	@PostMapping("getUserFollowLogPage")
	@Transactional
	open fun getUserFollowLogPage(@RequestBody vo: SickCustomerAccessLogSelectVo): ResponseBody {
		val followLogPage = iWebCompanyUserService.getFollowLogPage(getContext().userId, vo)
		for (accessLog in followLogPage.records) {
			iCustomerInfoService.getJoinInfoByCustomerId(accessLog.customerId,accessLog)
		}
		return returnSuccess(followLogPage)
	}

	/**
	 * 分院随访分页查询
	 */
	@PostMapping("getSubCompanyLogPage")
	@PermsCode("customer:access:subCompany:follow:list")
	@Transactional
	open fun getSubCompanyLogPage(@RequestBody vo: SickCustomerAccessLogSelectVo): ResponseBody {
		vo.type = TypeEnum.ACCESS_LOG_FOLLOW_UP
		val accessLogPage = iWebCompanyDeptService.getAccessLogPage(
			Page<SickCustomerAccessLog>(vo.current, vo.size),vo)
		for (accessLog in accessLogPage.records) {
			iCustomerInfoService.getJoinInfoByCustomerId(accessLog.customerId,accessLog)
		}
		return returnSuccess(accessLogPage)
	}

	/**
	 * 分院今日随访分页查询
	 */
	@PostMapping("getTodaySubCompanyLogPage")
	@PermsCode("customer:access:subCompany:follow:list")
	@Transactional
	open fun getTodaySubCompanyLogPage(@RequestBody vo: SickCustomerAccessLogSelectVo): ResponseBody {
		vo.type = TypeEnum.ACCESS_LOG_FOLLOW_UP
		if (vo.planDay == null) {
			vo.planDay = Date()
		}
		val accessLogPage = iWebCompanyDeptService.getAccessLogPage(
			Page<SickCustomerAccessLog>(vo.current, vo.size),vo)
		for (accessLog in accessLogPage.records) {
			iCustomerInfoService.getJoinInfoByCustomerId(accessLog.customerId,accessLog)
		}
		return returnSuccess(accessLogPage)
	}

	/**
	 * 分院今日随访列表查询
	 */
	@PostMapping("getSubCompanyTodayLogPage")
	@PermsCode("customer:access:subCompany:follow:today:list")
	@Transactional
	open fun getSubCompanyTodayLogPage(@RequestBody vo: SickCustomerAccessLogSelectVo): ResponseBody {
		vo.type = TypeEnum.ACCESS_LOG_FOLLOW_UP
		if (vo.planDay == null) {
			vo.planDay = Date()
		}
		val accessLogPage = iWebCompanyDeptService.getAccessLogPage(
			Page<SickCustomerAccessLog>(vo.current, vo.size),
			vo
		)
		for (accessLog in accessLogPage.records) {
			 iCustomerInfoService.getJoinInfoByCustomerId(accessLog.customerId,accessLog)
		}
		return returnSuccess(
			accessLogPage
		)
	}



	/**
	 * 分院今日随访数量查询
	 */
	@GetMapping("getSubCompanyTodayLogCount")
	@PermsCode("customer:access:subCompany:follow:today:list")
	@Transactional
	open fun getSubCompanyTodayLogCount(): ResponseBody {
		return returnSuccess(
			iWebCompanyDeptService.getAccessLogCount(
				SickCustomerAccessLogSelectVo(
					type = TypeEnum.ACCESS_LOG_FOLLOW_UP,
					planDay = Date()
				)
			)
		)
	}

	/**
	 * 分院今日随访完成数量查询
	 */
	@GetMapping("getSubCompanyTodayLogCompleteCount")
	@PermsCode("customer:access:subCompany:follow:today:list")
	@Transactional
	open fun getSubCompanyTodayLogCompleteCount(): ResponseBody {
		return returnSuccess(
			iWebCompanyDeptService.getAccessLogCount(
				SickCustomerAccessLogSelectVo(
					type = TypeEnum.ACCESS_LOG_FOLLOW_UP,
					planDay = Date(),
					accessIsComplete = true,
				)
			)
		)
	}

	/**
	 * 分院今日随访未完成数量查询
	 */
	@GetMapping("getSubCompanyTodayLogUnCompleteCount")
	@PermsCode("customer:access:subCompany:follow:today:list")
	@Transactional
	open fun getSubCompanyTodayLogUnCompleteCount(): ResponseBody {
		return returnSuccess(
			iWebCompanyDeptService.getAccessLogCount(
				SickCustomerAccessLogSelectVo(
					type = TypeEnum.ACCESS_LOG_FOLLOW_UP,
					planDay = Date(),
					accessIsComplete = false,
				)
			)
		)
	}

	/**
	 * 获取随访详情（目前随访，回访都能获取）
	 */
	@GetMapping("getAccessLogById/{id}")
	@Transactional
	open fun getAccessLogById(@PathVariable id: Long): ResponseBody {
		val accessLog = iSickCustomerAccessLogService.getById(id) ?: return returnSuccess()
		val createUser = iCompanyUserService.getUser(accessLog.createUserId)
		if (createUser != null) {
			accessLog.createUserName = createUser.realName
		}
		val doctor = iCompanyUserService.getUser(accessLog.doctorId)
		if (doctor != null) {
			accessLog.doctorName = doctor.realName
		}
		val dealUser = iCompanyUserService.getUser(accessLog.dealUserId)
		if (dealUser != null) {
			accessLog.dealUserName = dealUser.realName
		}
		if (accessLog.consultantId != null) {
			val consultantUser = iCompanyUserService.getUser(accessLog.consultantId!!)
			if (consultantUser != null) {
				accessLog.consultantName = consultantUser.realName
			}
		}

		val lastLog = iCustomerInfoService.getLastCompleteAccessLog(accessLog.customerId, accessLog.type)
		if (lastLog != null) {
			accessLog.lastBackContent = lastLog.backContent
		}

		return returnSuccess(accessLog)
	}


	/**
	 * 客户回访列表查询
	 */
	@PostMapping("getVisitLogList")
	@PermsCode("customer:access:visit:show")
	@Transactional
	open fun getVisitLogList(@RequestBody vo: SickCustomerAccessLogSelectVo): ResponseBody {
		vo.type = TypeEnum.ACCESS_LOG_RETURN_VISIT
		if (vo.customerId == null) {
			return returnError(ErrorCode.PARAM_EMPTY, "请选择客户")
		}
		val accessLogList = iCustomerInfoService.getAccessLogList(vo)
		for (accessLog in accessLogList) {
			iCustomerInfoService.getJoinInfoByCustomerId(accessLog.customerId,accessLog)
		}
		return returnSuccess(accessLogList)
	}

	/**
	 * 分院回访列表查询
	 */
	@PostMapping("getSubCompanyVisitLogPage")
	@PermsCode("customer:access:subCompany:visit:list")
	@Transactional
	open fun getSubCompanyVisitLogPage(@RequestBody vo: SickCustomerAccessLogSelectVo): ResponseBody {
		vo.type = TypeEnum.ACCESS_LOG_RETURN_VISIT
		val accessLogPage = iWebCompanyDeptService.getAccessLogPage(
			Page<SickCustomerAccessLog>(vo.current, vo.size),
			vo
		)
		for (accessLog in accessLogPage.records) {
			iCustomerInfoService.getJoinInfoByCustomerId(accessLog.customerId,accessLog)
		}
		return returnSuccess(accessLogPage)
	}

	/**
	 * 添加随访计划
	 */
	@PostMapping("addAccessLogList")
	@Transactional(rollbackFor = [Exception::class])
	open fun addAccessLogList(@RequestBody list: List<SickCustomerAccessLog>): ResponseBody {
		var i = 1
		for (item in list) {
			item.type = TypeEnum.ACCESS_LOG_FOLLOW_UP
			val createAccessLog = iCustomerInfoService.createAccessLog(item)
			if (createAccessLog.bodyIsError()) {
				TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
				return returnError(ErrorCode.OPERATION_DATA_ERROR, "第" + i + "条随访错误：" + createAccessLog.msg)
			}
			i++
		}
		return returnSuccess()
	}

	/**
	 * 添加一条完成的随访记录
	 */
	@PostMapping("addCompleteFollowAccessLog")
	@Transactional(rollbackFor = [Exception::class])
	open fun addCompleteFollowAccessLog(@RequestBody accessLog: SickCustomerAccessLog): ResponseBody {
		accessLog.type = TypeEnum.ACCESS_LOG_FOLLOW_UP
		val createAccessLog = iCustomerInfoService.createAccessLog(accessLog)
		if (createAccessLog.bodyIsError()) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
			return createAccessLog
		}
		if (accessLog.backContent.isNullOrEmpty()) {
			returnError(ErrorCode.PARAM_EMPTY, "请输入访问结果")
		}
		val dealContent =
			iSickCustomerAccessLogService.setDealContent(
				accessLog.id,
				accessLog.backContent!!,
				accessLog.remark,
				accessLog.contactType
			)
		if (dealContent.bodyIsError()) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
			return dealContent
		}
		val completeLog = iSickCustomerAccessLogService.completeLog(accessLog.id)
		if (completeLog.bodyIsError()) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
			return completeLog
		}
		return returnSuccess()
	}

	/**
	 * 修改随访计划（未完成的）
	 */
	@PostMapping("updateCompleteFollowAccessPlan")
	@Transactional(rollbackFor = [Exception::class])
	open fun updateCompleteFollowAccessPlan(@RequestBody accessLog: SickCustomerAccessLog): ResponseBody {
		val updatePlan = iSickCustomerAccessLogService.updatePlan(accessLog)
		if (updatePlan.bodyIsError()) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
			return updatePlan
		}
		return returnSuccess()
	}

	/**
	 * 修改随访记录（完成的）
	 */
	@PostMapping("updateCompleteFollowAccessLog")
	@Transactional(rollbackFor = [Exception::class])
	open fun updateCompleteFollowAccessLog(@RequestBody accessLog: SickCustomerAccessLog): ResponseBody {
		val updatePlan = iSickCustomerAccessLogService.updatePlan(accessLog)
		if (updatePlan.bodyIsError()) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
			return updatePlan
		}
		val updateBackContent = iSickCustomerAccessLogService.updateBackContent(accessLog)
		if (updateBackContent.bodyIsError()) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
			return updateBackContent
		}
		return returnSuccess()
	}

	/**
	 * 获取正在进行的订单项目
	 */
	@GetMapping("getCustomerOnGoingServiceItemList/{customerId}")
	@Transactional
	open fun getCustomerOnGoingServiceItemList(@PathVariable customerId: Long): ResponseBody {
		// TODO: 2021/8/21 暂时没地方处理正在进行的订单明细状态，所以暂时不管  即使完成的，可能还会使用！
		val vo = PayCustomerOrderDetailSelectVo(
			customerId = customerId,
			itemType = TypeEnum.PAY_ITEM_SERVICE
		)
		val orderDetailList = iCustomerInfoService.getOrderDetailList(customerId, vo)
		val resList = mutableListOf<Map<String, Any>>()
		for (detail in orderDetailList) {
			val map = mutableMapOf<String, Any>()
			map["id"] = detail.id
			map["name"] = detail.itemName!!
			resList.add(map)
		}
		return returnSuccess(resList)
	}

	/**
	 * 执行回访，随访
	 */
	@PostMapping("completeAccessLog")
	@Transactional(rollbackFor = [Exception::class])
	@PermsCode("customer:access:perform")
	open fun completeAccessLog(@RequestBody accessLog: SickCustomerAccessLogCompleteVo): ResponseBody {

		val dealContent =
			iSickCustomerAccessLogService.setDealContent(
				accessLog.id,
				accessLog.backContent,
				accessLog.remark,
				accessLog.contactType
			)
		if (dealContent.bodyIsError()) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
			return dealContent
		}
		val completeLog = iSickCustomerAccessLogService.completeLog(accessLog.id)
		if (completeLog.bodyIsError()) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
			return completeLog
		}

		return returnSuccess()
	}


	/**
	 * 执行回访(全部患者处)
	 */
	@PostMapping("completeAccessVisitLog")
	@Transactional(rollbackFor = [Exception::class])
	@PermsCode("customer:access:visit:perform")
	open fun completeAccessVisitLog(@RequestBody accessLog: SickCustomerAccessLogCompleteVo): ResponseBody {

		val dealContent =
			iSickCustomerAccessLogService.setDealContent(
				accessLog.id,
				accessLog.backContent,
				accessLog.remark,
				accessLog.contactType
			)
		if (dealContent.bodyIsError()) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
			return dealContent
		}
		val completeLog = iSickCustomerAccessLogService.completeLog(accessLog.id)
		if (completeLog.bodyIsError()) {
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
			return completeLog
		}
		return returnSuccess()
	}

	/**
	 * 回访分页
	 */
	@PostMapping("getVisitLogPage")
	@Transactional
	open fun getVisitLogPage(@RequestBody vo: SickCustomerAccessLogSelectVo): ResponseBody {
		vo.type = TypeEnum.ACCESS_LOG_RETURN_VISIT
		val accessLogPage = iWebCompanyDeptService.getAccessLogPage(
			Page<SickCustomerAccessLog>(vo.current, vo.size),
			vo
		)
		for (accessLog in accessLogPage.records) {
			iCustomerInfoService.getJoinInfoByCustomerId(accessLog.customerId,accessLog)
		}
		return returnSuccess(accessLogPage)
	}

	/**
	 * 回访分页 自己的
	 */
	@PostMapping("getSelfVisitLogPage")
	@Transactional
	open fun getVisitLogPageByDoctorId(@RequestBody vo: SickCustomerAccessLogSelectVo): ResponseBody {
		vo.type = TypeEnum.ACCESS_LOG_RETURN_VISIT
		vo.doctorId = getContext().userId
		if(vo.planDay == null){
			vo.planDay = Date()
		}

		val accessLogPage = iWebCompanyDeptService.getAccessLogPage(
			Page<SickCustomerAccessLog>(vo.current, vo.size),
			vo
		)
		for (accessLog in accessLogPage.records) {
			iCustomerInfoService.getJoinInfoByCustomerId(accessLog.customerId,accessLog)
		}
		return returnSuccess(accessLogPage)
	}

	/**
	 * 随访访问类型
	 */
	@GetMapping("getAccessLogContactType")
	@Transactional
	open fun getAccessLogContactType(): ResponseBody {
		val list = mutableListOf<Map<String, Any>>()
		list.add(TypeEnum.ACCESS_LOG_CONTACT_PHONE.getMap())
		list.add(TypeEnum.ACCESS_LOG_CONTACT_SMS.getMap())
		list.add(TypeEnum.ACCESS_LOG_CONTACT_QQ.getMap())
		list.add(TypeEnum.ACCESS_LOG_CONTACT_WECHAT.getMap())
		list.add(TypeEnum.ACCESS_LOG_CONTACT_FACE_TO_FACE.getMap())
		list.add(TypeEnum.OTHER.getMap())
		return returnSuccess(list)
	}

	/**
	 * 随访项目
	 */
	@GetMapping("getAccessFollowItem")
	@Transactional
	open fun getCustomerImageType(): ResponseBody {
		return returnSuccess(
			iCompanyDictionaryService.getCompanyDetailListToMapIdName(
				Constants.DistId.ACCESS_FOLLOW_ITEM_SELECT,
				getContext().companyId,
				getContext().subCompanyId
			)
		)
	}

	/**
	 * 随访内容快捷方式
	 */
	@GetMapping("getAccessFollowContent")
	@Transactional
	open fun getAccessFollowContent(): ResponseBody {
		return returnSuccess(
			iCompanyDictionaryService.getCompanyDetailListToMap(
				Constants.DistId.ACCESS_FOLLOW_CONTENT_SELECT,
				getContext().companyId,
				getContext().subCompanyId
			)
		)
	}

	/**
	 * 随访返回结果快捷方式
	 */
	@GetMapping("getAccessFollowBackContent")
	@Transactional
	open fun getAccessFollowBackContent(): ResponseBody {
		return returnSuccess(
			iCompanyDictionaryService.getCompanyDetailListToMap(
				Constants.DistId.ACCESS_FOLLOW_BACK_CONTENT_SELECT,
				getContext().companyId,
				getContext().subCompanyId
			)
		)
	}

	/**
	 * 方案一 获取模版加明细，选的时候不请求接口 和对应医生，随访人固定id
	 */
	@GetMapping("getAccessModelAndDetail/{id}")
	@Transactional
	open fun getAccessModelAndDetail(@PathVariable id: Long):ResponseBody{
		val accessLogModelList =
			iWebCompanyDeptService.getAccessLogModelList(SickCustomerAccessLogModelSelectVo(status = Status.OPEN))
		for(model in accessLogModelList){
			iSickCustomerAccessLogModelService.setDetails(model)
		}
		val resMap = mutableMapOf<String,Any>()
		resMap["models"] = accessLogModelList
		resMap["doctors"] = createDoctorSelect(id)
		resMap["dealUsers"] = createConsultantSelect(id)
		return returnSuccess(resMap)
	}

	/**
	 *  获取模版加明细
	 */
	@GetMapping("getAccessModelAndDetailSelect")
	@Transactional
	open fun getAccessModelAndDetailSelect():ResponseBody{
		val accessLogModelList =
			iWebCompanyDeptService.getAccessLogModelList(SickCustomerAccessLogModelSelectVo(status = Status.OPEN))
		for(model in accessLogModelList){
			iSickCustomerAccessLogModelService.setDetails(model)
		}
		return returnSuccess(accessLogModelList)
	}

	/**
	 * 获取医生
	 */
	@GetMapping("getAccessDoctorSelect/{id}")
	@Transactional
	open fun getAccessDoctorSelect(@PathVariable id: Long):ResponseBody{

		return returnSuccess(createDoctorSelect(id))
	}

	/**
	 * 获取随访人
	 */
	@GetMapping("getDealUserSelect/{id}")
	@Transactional
	open fun getDealUserSelect(@PathVariable id: Long):ResponseBody{
		return returnSuccess(createConsultantSelect(id))
	}





	/**
	 * 创建随访计划
	 */
	@PostMapping("createAccessPlan")
	@Transactional(rollbackFor = [Exception::class])
	open fun createAccessPlan(@RequestBody plan: SickCustomerAccessLogPlan):ResponseBody{
		val createAccessPlan = iCustomerInfoService.createAccessPlan(plan)
		if(createAccessPlan.bodyIsError()){
			TransactionAspectSupport.currentTransactionStatus().setRollbackOnly()
			return createAccessPlan
		}
		if(plan.createType == TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_CREATE_TYPE_CREATE_ALL){
			var standardTime = plan.sickTime
			//一次性创建所有
			for(detail in plan.details!!){
				iCustomerInfoService.createAccessLogByPlanDetail(plan,standardTime,detail)

				if(plan.createTimeType == TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_CRATE_TIME_INTERVAL_TYPE_LAST){
					standardTime = addTimeByType(standardTime,detail.timeNumber,detail.timeType)
				}

			}
		}else{
			//完成时创建下一个
			val detail = plan.details!![0]
			iCustomerInfoService.createAccessLogByPlanDetail(plan,plan.sickTime,detail)

		}
		return returnSuccess()
	}


	private fun createDoctorSelect(customerId:Long):MutableList<UserByTypeVo>{
		val resList = mutableListOf<UserByTypeVo>()
		val firstSickDoctor = iCustomerInfoService.getCustomerFirstSickDoctor(customerId)
		addUserToSelectList(resList,firstSickDoctor,
			TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DOCTOR_TYPE_FIRST_SICK_DOCTOR
		)
		val sickDoctor = iCustomerInfoService.getCustomerSickDoctor(customerId)
		addUserToSelectList(resList,sickDoctor,
			TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DOCTOR_TYPE_SICK_DOCTOR
		)
		val customerResponsibilityDoctor = iCustomerInfoService.getCustomerResponsibilityDoctor(customerId)
		addUserToSelectList(resList,customerResponsibilityDoctor,
			TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DOCTOR_TYPE_RESPONSIBILITY_FOR_THE_DOCTOR
		)
		addUserToSelectList(resList,null,
			TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DOCTOR_TYPE_OTHER_DOCTOR
		)

		return resList
	}

	private fun createConsultantSelect(customerId:Long):MutableList<UserByTypeVo>{
		val resList = mutableListOf<UserByTypeVo>()
		val customerFirstSickConsultant = iCustomerInfoService.getCustomerFirstSickConsultant(customerId)
		addUserToSelectList(resList,customerFirstSickConsultant,
			TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DEAL_USER_TYPE_FIRST_SICK_CONSULTANT
		)
		val customerSickConsultant = iCustomerInfoService.getCustomerSickConsultant(customerId)
		addUserToSelectList(resList,customerSickConsultant,
			TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DEAL_USER_TYPE_SICK_CONSULTANT
		)
		val customerConsultant = iCustomerInfoService.getCustomerConsultant(customerId)
		addUserToSelectList(resList,customerConsultant,
			TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DEAL_USER_TYPE_CONSULTANT
		)
//		val customerNetConsultant = iCustomerInfoService.getCustomerNetConsultant(customerId)
//		addUserToSelectList(resList,customerNetConsultant,
//			TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DEAL_USER_TYPE_NET_CONSULTANT
//		)

		addUserToSelectList(resList,null,
			TypeEnum.SICK_CUSTOMER_ACCESS_LOG_MODEL_DETAIL_DEAL_USER_TYPE_OTHER
		)


		return resList
	}

	private fun  addUserToSelectList(list:MutableList<UserByTypeVo>,user:CompanyUser?,selectType:TypeEnum){
		if(user != null){
			list.add(UserByTypeVo(
				typeValue = selectType.typeName,
				showValue = selectType.typeName+":"+user.realName,
				userId = user.id
			))
		}else{
			list.add(UserByTypeVo(
				typeValue = selectType.typeName,
				showValue = selectType.typeName
			))
		}
	}



	data class UserByTypeVo(
		val typeValue:String,
		val showValue:String,
		val userId:Long?=null
	)


}
